package com.kye.express.business.jpush;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.kye.express.business.base.BaseAppCompatActivity;
import com.kye.model.bean.jpush.PushFeedbackModel;
import com.kye.model.bean.jpush.PushNewsModel;
import com.kye.model.bean.jpush.PushPlaceOrderModel;

/**
 * push消息dialog展示
 */
public class JpushDialogActivity extends BaseAppCompatActivity {

    public static void showOtherLoginDialog(Context context, PushPlaceOrderModel pushPlaceOrderModel) {
        Intent intent = new Intent(context, JpushDialogActivity.class);
        intent.putExtra(JpushDialogArgKeyUtils.ARG_DATA, pushPlaceOrderModel);
        intent.putExtra(JpushDialogArgKeyUtils.ARG_ACTION_ID, JpushDialogArgKeyUtils.PushDialogActionId.otherLogin);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showNoticeDialog(Context context, PushNewsModel pushNewsModel) {
        Intent intent = new Intent(context, JpushDialogActivity.class);
        intent.putExtra(JpushDialogArgKeyUtils.ARG_DATA, pushNewsModel);
        intent.putExtra(JpushDialogArgKeyUtils.ARG_ACTION_ID, JpushDialogArgKeyUtils.PushDialogActionId.notice);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void showFeedbackDialog(Context context, PushFeedbackModel pushFeedbackModel) {
        Intent intent = new Intent(context, JpushDialogActivity.class);
        intent.putExtra(JpushDialogArgKeyUtils.ARG_DATA, pushFeedbackModel);
        intent.putExtra(JpushDialogArgKeyUtils.ARG_ACTION_ID, JpushDialogArgKeyUtils.PushDialogActionId.feedback);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        JpushDialogArgKeyUtils.PushDialogActionId actionId = (JpushDialogArgKeyUtils.PushDialogActionId) getIntent().getSerializableExtra(JpushDialogArgKeyUtils.ARG_ACTION_ID);
        if (actionId == null) {
            finish();
        }

        if (actionId == JpushDialogArgKeyUtils.PushDialogActionId.otherLogin) {
            JpushDialogFragment.newOtherLoginDialog((PushPlaceOrderModel) getIntent().getSerializableExtra(JpushDialogArgKeyUtils.ARG_DATA)).show(getSupportFragmentManager(), "otherLoginDialog");
        } else if (actionId == JpushDialogArgKeyUtils.PushDialogActionId.notice) {
            JpushDialogFragment.newNoticeDialog((PushNewsModel) getIntent().getSerializableExtra(JpushDialogArgKeyUtils.ARG_DATA)).show(getSupportFragmentManager(), "noticeDialog");
        } else if (actionId == JpushDialogArgKeyUtils.PushDialogActionId.feedback) {
            JpushDialogFragment.newFeedbackDialog((PushFeedbackModel) getIntent().getSerializableExtra(JpushDialogArgKeyUtils.ARG_DATA)).show(getSupportFragmentManager(), "feedbackDialog");
        }
    }
}
